package chapter9_Buffer;

import java.io.*;
import java.io.Serializable;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ObjectInputTest {
	public static void main(String[] args) {
		
		long timeStart = System.currentTimeMillis();
		try {
			ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("C:\\Users\\WYH\\Desktop\\java11.txt"));
			ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("C:\\Users\\WYH\\Desktop\\java12.txt"));
			Student student = null;
			while ( (student = (Student)objectInputStream.readObject() ) != null ) {
				student.setScore(100);
				System.out.println(student);
				objectOutputStream.writeObject(student);
			}
			objectInputStream.close();
			objectOutputStream.flush();
			objectOutputStream.close();
		}catch ( EOFException e ){ 
			
		}catch ( StreamCorruptedException e) {
			e.printStackTrace();
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e){
			e.printStackTrace();
		}finally {
			long timeEnd = System.currentTimeMillis();
			System.out.println("使用缓冲流花费的时间为：" + (timeEnd - timeStart) + "ms");
		}
	}
}
